# -*- coding: utf-8 *-*
import unittest
from graphs.listgraph import ListGraph
from graphs.matrixgraph import MatrixGraph


class DijkstraTest(unittest.TestCase):

    def test_dijkstra_matrix(self):
        self.run_test1(MatrixGraph())
        self.run_test2(MatrixGraph())
        self.run_test3(MatrixGraph())

    def test_dijkstra_list(self):
        self.run_test1(ListGraph())
        self.run_test2(ListGraph())
        self.run_test3(ListGraph())

    def run_test1(self, graph):
        graph.load('inputs/test1.txt')

        path = graph.run_dijkstra('s', 'z')

        self.assertEqual('s', path.pop_first())
        self.assertEqual('u', path.pop_first())
        self.assertEqual('x', path.pop_first())
        self.assertEqual('z', path.pop_first())

    def run_test2(self, graph):
        graph.load('inputs/test2.txt')

        path = graph.run_dijkstra('s', 'z')

        self.assertEqual('s', path.pop_first())
        self.assertEqual('u', path.pop_first())
        self.assertEqual('v', path.pop_first())
        self.assertEqual('x', path.pop_first())
        self.assertEqual('y', path.pop_first())
        self.assertEqual('z', path.pop_first())

    def run_test3(self, graph):
        graph = ListGraph()
        graph.load('inputs/test3.txt')

        path = graph.run_dijkstra('a', 'e')

        self.assertEqual('a', path.pop_first())
        self.assertEqual('c', path.pop_first())
        self.assertEqual('e', path.pop_first())
